/**
 * Created by ZFL on 2018/1/10.
 */

var vm = new Vue({
    el:'#saleEle',
    data:{
        SaleData:[]         //售后单子
    },
    methods:{
        goChildPage:function(item){
            var customerData = item;
            var afterSalesId = item.afterSalesId;
            $.setStorage('customerData',customerData);
            window.location.href = 'customer_inf.html?afterSalesId='+item.afterSalesId;
        }
    }
});

var userId = 0;
function PageInit(){
    if(com_obj.userId != ''){
        userId = com_obj.userId;
    }
    getSaleData();      //获取售后列表
}
function appInit(){
    PageInit();
}

//获得用户售后单子
var pageNum = 1;
var pageSize = 10;
var loading = false;
function getSaleData(){
    // status 0平台拒绝 1待处理 2退货退款中 3已退款 4已拒绝
    $.ajaxHandler({
        model: function () {
            var obj = {};
            obj.pageNum = pageNum;
            obj.pageSize = pageSize;
            obj.userId = userId;
            if(com_obj.mallStoreId){
                obj.storeId=com_obj.mallStoreId;

            }else{
                obj.storeId= $.getStorage('mallStoreId');
                com_obj.mallStoreId= $.getStorage('mallStoreId');
            }

            console.log(obj)
            return obj;
        },
        visibleTime: 0,
        dataType: "json",
        approve: true,
        visible:'hide',
        api: 'yg_baijiaplatform/afterSales/ygBaFindUserAfterSalesList',
        success: function (result) {
            //console.log(result);
            if(result.code == 10000){
                var data = result.data;
                if(data.length > 0){
                    loading = false;
                    //说明售后有数据
                    data.forEach(function(value,index){
                        value.statusText = '';
                        if(value.status == 1){//0平台拒绝 1待处理 2已同意 3已完成 4已拒绝
                            value.statusText = '待处理';
                        }else if(value.status == 2 && value.isRefund ==1){//1退款 2退货退款
                            value.statusText = '退款中';
                        }else if(value.status == 2 && value.isRefund ==2){//1退款 2退货退款
                            value.statusText = '退货退款中';
                        }else if(value.status == 3 && value.isRefund ==1){//1退款 2退货退款
                            value.statusText = '已退款';
                        }else if(value.status == 3 && value.isRefund ==2){//1退款 2退货退款
                            value.statusText = '已退货退款';
                        }else if(value.status == 4){//1退款 2退货退款
                            value.statusText = '已拒绝';
                        }
                        value.refundMoney = divideNumber(value.refundMoney,100);
                        value.salePrice = divideNumber(value.salePrice,100);
                        vm.SaleData.push(value);
                    })
                }else {
                    if(pageNum == 1){
                        $(".shop-goods-warp").css("background","#ffffff").html('<li style="text-align: center; padding-top: 68px;padding-bottom:10rem;"><img style="display: inline-block; width: 3.4933rem; height: 2.9866rem; margin-bottom: .2666rem;" src="/b2c/images/customerSer/null.png"><p style="font-size: 14px;color: #bbbbbb;">暂无售后订单数据~</p></li>');

                    }
                    //说明没有售后数据
                    if(pageNum > 1){
                        loading = true;
                        YDUI.dialog.toast('加载完啦~', 'none', 1000);
                    }


                }
            }else {
                YDUI.dialog.toast(result.message, 'error', 1000);
            }
        }
    })
}

//滚动加载数据
window.onscroll = function(){
    //当地址列表页面打开的情况下 加载地址列表
    var scr = $(window).scrollTop();
    var clientH = document.body.clientHeight;
    var scrollH = document.body.scrollHeight;
    if(scr+clientH == scrollH){
        if(loading) return;
        loading = true;
        pageNum++;
        YDUI.dialog.loading.open('正在加载...');
        setTimeout(function(){
            getSaleData();
        },100);
    }
};

//返回
function returnPage(){
    history.go(-1);
}
